package com.kly.user.enums;

import com.fqgj.exception.enums.MsgCodeEnum;
import org.zalando.problem.StatusType;

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public enum ResultStatus implements StatusType ,MsgCodeEnum {
    CONTINUE(100, "继续", ""),
    SWITCHING_PROTOCOLS(101, "切换协议", ""),
    PROCESSING(102, "处理中", ""),
    CHECKPOINT(103, "检查点", ""),
    OK(200, "确定", ""),
    CREATED(201, "已创建", ""),
    ACCEPTED(202, "已接受", ""),
    NON_AUTHORITATIVE_INFORMATION(203, "非权威信息", ""),
    NO_CONTENT(204, "无内容", ""),
    RESET_CONTENT(205, "重置内容", ""),
    PARTIAL_CONTENT(206, "部分内容", ""),
    MULTI_STATUS(207, "多种状态", ""),
    ALREADY_REPORTED(208, "已经报告", ""),
    IM_USED(226, "IM已使用", ""),
    MULTIPLE_CHOICES(300, "多项选择", ""),
    MOVED_PERMANENTLY(301, "永久移动", ""),
    FOUND(302, "已找到", ""),
    SEE_OTHER(303, "参见其他", ""),
    NOT_MODIFIED(304, "未修改", ""),
    USE_PROXY(305, "使用代理", ""),
    TEMPORARY_REDIRECT(307, "临时重定向", ""),
    PERMANENT_REDIRECT(308, "永久重定向", ""),
    BAD_REQUEST(400, "错误请求", ""),
    UNAUTHORIZED(401, "未授权", ""),
    PAYMENT_REQUIRED(402, "需要付款", ""),
    FORBIDDEN(403, "禁止", ""),
    NOT_FOUND(404, "未找到", ""),
    METHOD_NOT_ALLOWED(405, "方法不允许", ""),
    NOT_ACCEPTABLE(406, "不可接受", ""),
    PROXY_AUTHENTICATION_REQUIRED(407, "需要代理认证", ""),
    REQUEST_TIMEOUT(408, "请求超时", ""),
    CONFLICT(409, "冲突", ""),
    GONE(410, "已消失", ""),
    LENGTH_REQUIRED(411, "需要长度", ""),
    PRECONDITION_FAILED(412, "前提条件失败", ""),
    REQUEST_ENTITY_TOO_LARGE(413, "请求实体过大", ""),
    REQUEST_URI_TOO_LONG(414, "请求URI过长", ""),
    UNSUPPORTED_MEDIA_TYPE(415, "不支持的媒体类型", ""),
    REQUESTED_RANGE_NOT_SATISFIABLE(416, "无法满足请求的范围", ""),
    EXPECTATION_FAILED(417, "预期失败", ""),
    I_AM_A_TEAPOT(418, "我是个茶壶", ""),
    UNPROCESSABLE_ENTITY(422, "无法处理的实体", ""),
    LOCKED(423, "已锁定", ""),
    FAILED_DEPENDENCY(424, "依赖失败", ""),
    UPGRADE_REQUIRED(426, "需要升级", ""),
    PRECONDITION_REQUIRED(428, "需要前提条件", ""),
    TOO_MANY_REQUESTS(429, "请求过多", ""),
    REQUEST_HEADER_FIELDS_TOO_LARGE(431, "请求头字段过大", ""),
    UNAVAILABLE_FOR_LEGAL_REASONS(451, "由于法律原因不可用", ""),
    INTERNAL_SERVER_ERROR(500, "内部服务器错误", ""),
    NOT_IMPLEMENTED(501, "未实施", ""),
    BAD_GATEWAY(502, "错误网关", ""),
    SERVICE_UNAVAILABLE(503, "服务不可用", ""),
    GATEWAY_TIMEOUT(504, "网关超时", ""),
    HTTP_VERSION_NOT_SUPPORTED(505, "不支持的HTTP版本", ""),
    VARIANT_ALSO_NEGOTIATES(506, "变体也在协商", ""),
    INSUFFICIENT_STORAGE(507, "存储空间不足", ""),
    LOOP_DETECTED(508, "检测到循环", ""),
    BANDWIDTH_LIMIT_EXCEEDED(509, "超出带宽限制", ""),
    NOT_EXTENDED(510, "未扩展", ""),
    NETWORK_AUTHENTICATION_REQUIRED(511, "需要网络认证", ""),


    //user相关异常
    /**
     * 禁止18岁一下人群使用
     */
    ILLEGAL_AGE(1001,"Not for use by persons under the age of 18 ", "禁止18岁一下人群使用"),
    /**
     * 用户表中不存在userCode
     */
    USER_NOT_EXIST(1002,"userCode does not exist in the user table", "用户表中不存在userCode"),

    INVALID_ACCOUNT_TYPE(1003,"invalid account type", "无效的帐户类型"),

    USER_REGISTRATION_NOT_COMPLETED(1004,"User did not complete registration or invalid user", "用户未完成注册或无效账户"),
    /**
     * 电话号码或验证码错误。
     */
    PHONE_VERIFICATION_FAILED(1005,"The phone number or verification code is wrong.", "电话号码或验证码错误。"),

    MISSING_USER_INFORMATION(1006,"Missing user information","用户信息缺失"),

    ACCOUNT_NOT_FOUND(1007,"Account not found","账号不存在"),

    INCORRECT_PASSWORD(1008,"Incorrect password","密码错误"),

    ACCOUNT_SUSPENDED(1009,"Your account has been suspended due to security issues","账号已被封禁"),

    //account相关
    ACCOUNT_IS_BOUND(1101,"Binding failed. Other account have been bound", "账号已绑定"),

    NO_ACCOUNT(1102,"The user has no bound account", "用户不存在已绑定账号"),

    DUPLICATE_ACCOUNT_TYPE(1103,"The user is already bound to the same type of account", "用户已绑定相同类型账号"),

    ILLEGAL_PARAMS(1104,"illegal parameter", ""),

    BINDING_ACCOUNT_EMPTY(1105,"Binding account cannot be empty","绑定账号不能为空"),


    GREETING_CODE_NOT_FOUND(1107, "This greetingCode does not exist in the table", "表中不存在此greetingCode"),

    ILLEGAL_USER_TYPE(1106, "Illegal userType type", "非法的userType类型"),

    ONLY_ONE_ACCOUNT(1108, "Can not remove the last account", "您无法取消最后一个帐户的关联"),

    CUSTOMER_ERROR(9999,"server exception", ""),




    //其他异常
    ILLEGAL_APPCODE(1201,"Illegal appCode","非法appCode"),

            ;
    private static final Map<Integer, ResultStatus> STATUSES = Arrays.stream(values()).
            collect(Collectors.collectingAndThen(Collectors.toMap
                    (ResultStatus::getStatusCode, Function.identity()), Collections::unmodifiableMap));
    private final int code;
    private final String reason;
    
    private final String comment;

    @Override
    public int getStatusCode() {
        return this.code;
    }

    @Override
    public String getReasonPhrase() {
        return this.reason;
    }

    private ResultStatus(final int statusCode, final String reasonPhrase, String comment) {
        this.code = statusCode;
        this.reason = reasonPhrase;
        this.comment = comment;
    }

    @Override
    public Integer getCode() {
        return this.code;
    }

    @Override
    public String getMsg() {
        return this.reason;
    }
}
